package com.shop.controllers;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.shop.models.ResultMap;
import com.shop.utils.PushImgUtil;
import com.shop.utils.StatusCode;

@Controller
public class PushImgController {
	@ResponseBody
	@RequestMapping(value="pushImg",produces="application/json;charset=utf-8",method={RequestMethod.POST})
	public String getResult(HttpServletRequest request)
	{
		String path="";
		Gson gson=new Gson();
		String result;
		if(PushImgUtil.pushImg(request,path))
		{
			result=gson.toJson(new ResultMap(StatusCode.SUCCESS,"上传成功！",path));
			System.out.println(result);
		}
		else
		{
			result=gson.toJson(new ResultMap(StatusCode.FAIL,"上传失败"));
			System.out.println(result);
		}
		return result;
	}
}
